package com.dyh.hissystem.util;

/**
 * @Author: daiyuhua
 * @Description: 封装返回结果
 */
public class RespUtil {
    private int code; //状态码
    private String message; //返回信息
    private Object data; //返回数据

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    //自定义返回结果
    public RespUtil(int code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    //封死无参构造
    private RespUtil(){}

    //成功返回结果
    public static RespUtil success(Object data){
        return new RespUtil(200,"成功",data);
    }

    //成功返回结果
    public static RespUtil success(String message){
        return new RespUtil(200,message,null);
    }

    //成功返回结果
    public static RespUtil success(){return  new RespUtil(200,null,null);}


    //服务器异常返回结果
    public static RespUtil error(Object data){
        return new RespUtil(200,"失败",data);
    }


    //服务器异常返回结果
    public static RespUtil error(String message){
        return new RespUtil(500,message,null);
    }

    public static RespUtil error(){return  new RespUtil(500,null,null);}

}
